<template>
    <mi-form-page @submit="submit"
                  :loading="edit.loading"
                  v-model:show="edit.show"
                  title="小程序配置"
    >
        <el-form :model="formData"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="show_type" label="短信平台">
                <mi-radio v-model="formData.show_type" :options="[{id:'ali',title:'阿里云'}, {id:'qixin',title:'企信'}]" />
            </el-form-item>


            <template v-if="formData?.show_type == 'ali'">
                <el-form-item prop="id" label="id">
                    <mi-input v-model="formData.ali.id" />
                </el-form-item>
                <el-form-item prop="secret" label="secret">
                    <mi-input v-model="formData.ali.secret" />
                </el-form-item>
                <el-form-item prop="sign" label="签名">
                    <mi-input v-model="formData.ali.sign" />
                </el-form-item>
            </template>

            <template v-else-if="formData?.show_type == 'qixin'">
                <el-form-item prop="url" label="地址">
                    <mi-input v-model="formData.qixin.url" />
                </el-form-item>
                <el-form-item prop="uid" label="企业ID">
                    <mi-input v-model="formData.qixin.uid" />
                </el-form-item>
                <el-form-item prop="account" label="账号">
                    <mi-input v-model="formData.qixin.account" />
                </el-form-item>
                <el-form-item prop="password" label="密码">
                    <mi-input v-model="formData.qixin.password" />
                </el-form-item>
            </template>

        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {reactive, watch, ref, onBeforeMount, inject, computed} from "vue";
import {simpleGet, simplePost} from "@/utils/request";
import {FormInstance} from "element-plus";
import Edit from "@/model/edit";

const url = '/site.siteConfig/edit'

const rules = {

}

const loading = ref(false)
const formRef = ref<FormInstance>()
const parentOptions = ref<any[]>([])
const edit = inject('sms', new Edit({}))

const formData = computed({
    get:() => {
        return edit.info?.value || {}
    },
    set:(data) => {
        edit.info.value = data
    }
})

const submit = () => {
    edit.submit({
        formRef: formRef.value,
        url: url,
    })
}

watch(() => edit.show, (nv,ov) => {
    edit.init(async () => {
        let {info} = await simpleGet(url, {key:'sms'})
        edit.info = info
        edit.info.value.qixin = info.value.qixin||{}
    })
})


</script>

<style scoped>

</style>

